<!DOCTYPE html>
<?php
	session_start();
?>
<html>
	<head>
		<meta http-equiv = "content-type" content = "text/html; charset = UTF-8">
		<title>我的主页-个人信息</title>
		<link rel = "stylesheet" href = "base.css">
		<style>
			div#content {
				width: 1190px;
				text-align: center;
				margin-top:0;
				float: left;
				
			}
			div#header {
				width: 1040px;
				text-align: center;
				float: left;
			}
			div#logo {
				width: 150px;
				float: left;
			}
			h1 {
				font-size: 18px;
			}
			a:link {
				text-decoration: none;
				color: blue;
			}
			a:visited {
				text-decoration: none;
				color: blue;
			}
			img#picture{
				text-align: center;
				margin-top: 50px;
			}
		</style>
	</head>
	<body class = "content">	
		<div id="container">
			<div id = "logo">
				<img src = "image/logo.gif"  width = "150px" height = "50px"/>
			</div>
			<div id = "header">
				<h1><a href = "index2.php">首页</a> | <a href = "msgboard.php">留言板</a> | <a href = "message.php">查看留言</a> | <a href = "userinfo.php">个人信息</a> | 
					<a href = "exit.php">退出</a></h1>
				<div id = "hello">
					<?php
					echo "$_SESSION[user] 你好！";
					?></div>
			</div>
		<div id = "content">
			<hr>
			<?php
	        include("conn.php");
	        include("page.php");
	        $userinfo = $_SESSION['user'];
	        $sql = "SELECT * FROM user WHERE username = '$userinfo'";
	        $sqlnum = "SELECT * FROM content WHERE username = '$userinfo'";          
	        $user = mysql_query($sql);
	        $content = mysql_query($sqlnum);
			$num = mysql_num_rows($content);
	        $pagecount = ceil($num/$pagesize);
	        if ($page<1)
	        {
	        	$page=1;$pageval=0;
	        }
	        else if ($page>$pagecount)
	        {
                $page=$pagecount;
                $pageval=($pagecount-1)*$pagesize;
            }
            else
            {
                $pageval=($page-1)*$pagesize;
            }
            if($page<=1)
            {
        		while($row=mysql_fetch_array($user))
               {
               		echo "<table align='center' cellpadding='5' border='0' bgcolor=#add3ef width=500>";
                    echo "<tr bgcolor=#D1EEEE><td>ID:$row[0]</td><td>用户名:$row[1]</td><td>email:$row[3]</td><td>注册时间:$row[4]</td></tr></table>";
                    echo "<table align='center' cellpadding='5' border='0' bgcolor=#add3ef width=500>";
                    echo "<tr bgcolor=#D1EEEE><td>发表过的留言：</td></tr></table>";
                }
            }
            $sql1 = "SELECT * FROM content WHERE username = '$userinfo' order by ID DESC  limit $pageval,$pagesize ";
            $query1= mysql_query($sql1);
            if($query1)
            {
	            while($row1=mysql_fetch_array($query1))
	            {
	            	echo "<table align='center'cellpadding='5' border='0' bgcolor=#add3ef width=500>";
	                echo"<tr bgcolor=#D1EEEE><td>标题:$row1[2]</td></tr>
	                <tr bgcolor=#eff3ff><td>内容:$row1[3]</td></tr>
	                <tr bgcolor=#EEE0E5><td>发表于：$row1[4]</td></tr>";
	                echo "<tr bgcolor=#fffeee><td><a href='edit.php?id=$row1[id]'</a>编辑 </a>|
	 				<a href=\"delete.php?id=$row1[id]\" onclick=\"if(confirm('确实要删除此条留言吗？')) return true;else return false; \" >删除</a></td></tr>";
	 			}
            	echo "</table>";
            	echo "<center>共有 $num 条记录,当前第".($pageval+1)."-".($page*$pagesize)."条<br></center>";
            }
            else
            {
            	echo "<tr bgcolor=#D1EEEE><td>暂无记录</td></tr>";
                echo "</table>";
            }
            if ($num>$pagesize)
            {
                if ($page<2)
                {
                    echo "<center>首页 上一页<a href=$url?page=".($page+1)."> 下一页</a>
                            <a href=$url?page=".($pagecount).">尾页</a></center>";
                }
                else if ($page>=$pagecount)
                {
                    echo "<center><a href=$url?page=1>首页</a><a href=$url?page=".($page-1)."> 上一页</a> 下一页 尾页</a></center>";
                }
                else
                {
                    echo"<center><a href=$url?page=1>首页</a><a href=$url?page=".($page-1)."> 上一页</a>
                        <a href=$url?page=".($page+1)."> 下一页</a><a href=$url?page=".($pagecount).">尾页</a></center>";
                }
     		}	
	       ?>
		</div>
		<div id="footer"><hr>Copyright © 2014 xiaolongge</div>
		</div>
	</body>
</html>